package com.ruoyi.dynamic.controller.app;

import com.ruoyi.common.core.annotation.NoRepeatSubmit;
import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.MultiVO;
import com.ruoyi.common.core.pojo.vo.SingleVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.RoomMomentRecord;
import com.ruoyi.dynamic.model.pojo.request.app.*;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomHeatResult;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomMomentSelResult;
import com.ruoyi.dynamic.service.IRoomMomentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "App-房间心动一刻相关", description = "App-房间心动一刻相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-moment")
public class AppRoomMomentController {

    private final IRoomMomentService iRoomMomentService;
    public AppRoomMomentController(IRoomMomentService iRoomMomentService) {
        this.iRoomMomentService = iRoomMomentService;
    }

    @Operation(summary = "主持获取当前活动状态 1自我介绍2自由发言3心动选择4自由发言5结果公布6结束", description = "开启心动一刻游戏 1自我介绍2自由发言3心动选择4自由发言5结果公布6结束")
    @PostMapping("findStatus")
    public SingleVO<AppRoomHeatResult> findStatus(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        AppRoomHeatResult id = iRoomMomentService.findStatus(request, userId);
        return Result.single(id);
    }

    @Operation(summary = "开启游戏", description = "开启游戏")
    @PostMapping
    public SingleVO<Long> openGame(@RequestBody @Validated AppRoomHeartCreateRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        Long id = iRoomMomentService.openGame(request, userId);
        return Result.single(id);
    }

    @Operation(summary = "申请星光嘉宾位", description = "申请星光嘉宾位")
    @GetMapping("apply-star-mai")
    public BaseVO applyStarMai(@Parameter(description = "房间id") Long id) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomMomentService.applyStarMai(userId, id);
        return Result.successOrFail(add);
    }

    @Operation(summary = "自我介绍完下一步自由发言", description = "自我介绍完下一步自由发言")
    @PostMapping("introOver")
    public BaseVO introOver(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.introOver(request, userId);
        return Result.success();
    }

    @Operation(summary = "自由发言结束开始心动选择", description = "自由发言结束开始心动选择")
    @PostMapping("makeOver")
    public BaseVO makeOver(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.makeOver(request, userId);
        return Result.success();
    }


    @Operation(summary = "心动选择结束开始自由发言", description = "心动选择结束开始自由发言")
    @PostMapping("selOver")
    public BaseVO selOver(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.selOver(request, userId);
        return Result.success();
    }


    @Operation(summary = "自由发言完下一步公布结果", description = "自由发言完下一步公布结果")
    @PostMapping("pushResult")
    public SingleVO<AppRoomMomentSelResult> pushResult(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        AppRoomMomentSelResult result = iRoomMomentService.pushResult(request, userId);
        return Result.single(result);
    }


    @Operation(summary = "选择她", description = "选择她")
    @PostMapping("starSel")
    public BaseVO starSel(@RequestBody @Validated AppRoomSelectMomentRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.starSel(request, userId);
        return Result.success();
    }


    @Operation(summary = "心动/不心动", description = "心动/不心动")
    @PostMapping("isHeart")
    public BaseVO isHeart(@RequestBody @Validated AppRoomSelHeartRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.isHeart(request, userId);
        return Result.success();
    }


    @Operation(summary = "放弃选择", description = "放弃选择")
    @PostMapping("giveUp")
    public BaseVO giveUp(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.giveUp(request, userId);
        return Result.success();
    }

    @Operation(summary = "获取当前游戏结果", description = "获取当前游戏结果")
    @GetMapping("getResult")
    public MultiVO<RoomMomentRecord> getResult(AppRoomHeartGetRequest request) {
        return Result.multi(iRoomMomentService.getResult(request.getRoomId(), request.getId()));
    }


    @Operation(summary = "星光嘉宾结束发言", description = "星光嘉宾结束发言")
    @PostMapping("starOverSay")
    public BaseVO starOverSay(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean id = iRoomMomentService.starOverSay(request, userId);
        return Result.single(id);
    }


    @NoRepeatSubmit
    @Operation(summary = "主播结束心动一刻游戏", description = "主播结束心动一刻游戏")
    @PostMapping("over")
    public BaseVO over(@RequestBody @Validated AppRoomHeartGetRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        iRoomMomentService.over(request, userId);
        return Result.success();
    }

}
